package com.liqiye.paymanager.controller;

import com.liqiye.paymanager.entity.Product;
import com.liqiye.paymanager.service.common.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @GetMapping("/list")
    public List<Product> list() {
        return productService.selectAll();
    }

    @PostMapping("/insert")
    public ResponseEntity<?> insert() {
        Product product = new Product();
        product.setName("产品-" + Math.random());
        productService.insert(product);
        return ResponseEntity.ok(product);
    }

    @PostMapping("/delete")
    public ResponseEntity<?> delete(String id) {
        productService.deleteById(id);
        return ResponseEntity.ok("success");
    }

}
